Skip to content

feat: Route binary operations through the shader generator - #2822

Merged
iwoplaza merged 1 commit into
feat/glsl-implicit-pointer-definitionsfrom
feat/route-bin-ops-through-generator
Aug 11, 2026
Merged

feat: Route binary operations through the shader generator#2822
iwoplaza merged 1 commit into
feat/glsl-implicit-pointer-definitionsfrom
feat/route-bin-ops-through-generator

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/eslint-plugin-typegpu@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@94707c72f18da2a708b83aebdd9a84d25a015c03
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@94707c72f18da2a708b83aebdd9a84d25a015c03

benchmark
view benchmark

commit
view commit

@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from b5d746f to 077d022 Compare August 10, 2026 10:06
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.97, 1.97, 4.32, 7.06, 8.00, 12.43, 22.99, 26.56]
  line [0.93, 2.00, 4.34, 7.22, 7.57, 12.45, 23.46, 26.07]
  line [0.94, 2.09, 4.70, 6.90, 8.44, 13.72, 24.29, 24.30]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.35, 0.56, 0.73, 0.87, 1.12, 1.24, 1.49, 1.65]
  line [0.35, 0.47, 0.69, 0.79, 1.16, 1.20, 1.41, 1.57]
  line [0.33, 0.54, 0.75, 0.96, 1.27, 1.33, 1.65, 1.69]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.90, 2.15, 4.14, 7.08, 12.49, 27.43, 56.80, 116.18]
  line [0.81, 2.21, 4.49, 6.98, 13.10, 27.09, 56.71, 117.59]
  line [1.07, 2.10, 4.28, 8.03, 14.22, 28.61, 61.53, 126.47]
Loading

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased (max -0.25%) ➖ Unchanged 🔴 Increased (max 2.79%) ❔ Unknown
6 130 187 1

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Test tsdown
std_isBeingTranspiled.ts 15.71 kB ($${\color{red}+2.8\%}$$)
std_getTargetShaderLanguage.ts 15.77 kB ($${\color{red}+2.8\%}$$)
STATIC_std.ts 110.10 kB ($${\color{red}+0.5\%}$$)
std_getShaderStage.ts 15.76 kB

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 270.69 kB ($${\color{green}-3.3\%}$$)
tgpu_initFromDevice.ts 270.15 kB ($${\color{green}-3.5\%}$$)
tgpu_resolve.ts 170.93 kB ($${\color{green}-38.9\%}$$)
tgpu_resolveWithContext.ts 170.87 kB ($${\color{green}-39.0\%}$$)
tgpu_bindGroupLayout.ts 73.93 kB ($${\color{green}-73.6\%}$$)
tgpu_mutableAccessor.ts 68.66 kB ($${\color{green}-75.5\%}$$)
tgpu_accessor.ts 68.66 kB ($${\color{green}-75.5\%}$$)
tgpu_privateVar.ts 67.35 kB ($${\color{green}-75.9\%}$$)
tgpu_workgroupVar.ts 67.35 kB ($${\color{green}-75.9\%}$$)
tgpu_const.ts 66.77 kB ($${\color{green}-76.1\%}$$)
tgpu_lazy.ts 66.56 kB ($${\color{green}-76.2\%}$$)
tgpu_fragmentFn.ts 38.92 kB ($${\color{green}-86.1\%}$$)
tgpu_fn.ts 38.87 kB ($${\color{green}-86.1\%}$$)
tgpu_vertexFn.ts 38.74 kB ($${\color{green}-86.2\%}$$)
tgpu_computeFn.ts 38.44 kB ($${\color{green}-86.3\%}$$)
tgpu_vertexLayout.ts 27.57 kB ($${\color{green}-90.2\%}$$)
tgpu_comptime.ts 15.18 kB ($${\color{green}-94.6\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 kB ($${\color{green}-99.4\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Minor suggestions only — one small typo in an error message.

Reviewed changes

  • emitBinaryOp route — Added emitBinaryOp plus the BinaryOperator union to the ShaderGenerator interface and WgslGenerator, and rewired + - * / % << >> in std/operators.ts and the binary-expression emitter through it (replacing inline stitch and the old parenthesization block).
  • Method renames — Renamed the unstable ShaderGenerator methods callemitCall and typeAnnotationemitTypeAnnotation across WgslGenerator, GlslGenerator, internal.ts, resolutionCtx.ts, and every std codegen call site. All callers were updated.
  • _callShellless extraction — Factored the shellless-call lowering out of _expression into a reusable protected WgslGenerator._callShellless, and reused it from GlslGenerator.emitBinaryOp to translate floating-point % into a remainder shell helper (GLSL ES has no float %), leaving non-float % on the super path.

The parenthesization and operator-mapping behavior is preserved for WGSL, so existing WGSL snapshots should be unaffected.

ℹ️ Nitpicks

  • packages/typegpu-gl/src/glslGenerator.ts:430 — error message has a doubled (type: prefix on the RHS operand.
  • The %remainder path in the new test only covers scalar f32; vec2f/3f/4f operands hit the same branch but aren't exercised.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu-gl/src/glslGenerator.ts Outdated
Copilot AI lite review requested due to automatic review settings August 10, 2026 10:17
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from 077d022 to 728fda6 Compare August 10, 2026 10:17
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from 728fda6 to 74bc6ff Compare August 10, 2026 10:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes emission of binary operations (and related helpers like function calls/type annotations) behind the ShaderGenerator interface so language backends (notably GLSL) can customize operator lowering while reusing the same TGSL resolution pipeline.

Changes:

  • Add emitBinaryOp to ShaderGenerator and route TGSL binary/assignment/logical operator emission through it.
  • Rename typeAnnotation/call to emitTypeAnnotation/emitCall and update stdlib + resolution code to use the new API.
  • Extend the GLSL generator to lower floating-point % to a generated remainder helper, with a new regression test.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/typegpu/src/tgsl/wgslGenerator.ts Adds _callShellless, routes binary ops via emitBinaryOp, renames generator emission helpers.
packages/typegpu/src/tgsl/shellless.ts Makes ShelllessRepository.get accept readonly snippet arrays.
packages/typegpu/src/tgsl/shaderGenerator.ts Extends generator interface with emitBinaryOp and renames emission methods.
packages/typegpu/src/std/operators.ts Routes arithmetic/shift operator codegen via ctx.gen.emitBinaryOp (and generator-driven instantiation).
packages/typegpu/src/std/numeric.ts Updates built-in call emission to emitCall.
packages/typegpu/src/std/boolean.ts Updates built-in call emission to emitCall.
packages/typegpu/src/std/bitcast.ts Updates built-in call emission to emitCall.
packages/typegpu/src/std/array.ts Updates built-in call emission to emitCall.
packages/typegpu/src/resolutionCtx.ts Updates schema-to-type annotation emission to emitTypeAnnotation.
packages/typegpu/src/internal.ts Re-exports BinaryOperator from internal API surface.
packages/typegpu-gl/tests/glslGenerator.test.ts Adds test ensuring float % becomes a remainder() call in GLSL output.
packages/typegpu-gl/src/glslGenerator.ts Implements GLSL-specific % lowering via a shellless remainder helper and updates renamed methods.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/typegpu/src/tgsl/shaderGenerator.ts Outdated
Comment thread packages/typegpu-gl/src/glslGenerator.ts Outdated

@cieplypolar cieplypolar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread packages/typegpu-gl/src/glslGenerator.ts Outdated
Comment thread packages/typegpu/src/tgsl/shaderGenerator.ts
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch 2 times, most recently from e4d25cd to a1ffa8d Compare August 11, 2026 09:19
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from a1ffa8d to 141d651 Compare August 11, 2026 09:25
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from 141d651 to f027104 Compare August 11, 2026 13:35
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from f027104 to cc0f470 Compare August 11, 2026 14:44
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from cc0f470 to 26834db Compare August 11, 2026 14:50
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from b52e007 to eae3134 Compare August 11, 2026 15:02
@pullfrog

pullfrog Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from eae3134 to 4050ec3 Compare August 11, 2026 15:48
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from 4050ec3 to 3a3e613 Compare August 11, 2026 16:42
Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@iwoplaza
iwoplaza force-pushed the feat/route-bin-ops-through-generator branch from 3a3e613 to 94707c7 Compare August 11, 2026 18:04
@iwoplaza
iwoplaza merged commit 8dd8255 into main Aug 11, 2026
13 of 17 checks passed
@iwoplaza
iwoplaza deleted the feat/route-bin-ops-through-generator branch August 11, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants